<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>lamp demo</title>
    <script src="../../lib/vue-dev/dist/vue.min.js"></script>
</head>
<body>
    <div id="app"> 
            <input type="button" value="跑起来" @click="start">
            <input type="button" value="停下来" @click="stop">
            <h4>{{ msg }}</h4>
    </div>
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                msg: '这是个跑马灯。。。。！！！！',
                intervalId: null
            },
            methods: {
                start() {
                    if(null != this.intervalId) {
                        return;
                    } else {
                        this.intervalId = setInterval(() => {
                            var start = this.msg.substring(0, 1);
                            var end = this.msg.substring(1);
                            this.msg = end + start;
                        }, 50);
                    }
                },
                stop() {
                    clearInterval(this.intervalId);
                    this.intervalId = null;
                }
            }
        });
    </script>
</body>
</html>